<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.css">
    <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css">
    <link rel="stylesheet" href="../../static/css/mycss.css">
    <title>博客发布</title>
</head>
<body>
<!--导航-->
<nav th:replace="admin/_fragments :: menu(1)" class="ui inverted attached segment my-padding-small my-shadow-small"><!--attached会连接上一个模块，没有缝隙-->
    <div class="iu container">
        <div class="ui inverted secondary stackable menu"> <!--menu导航条;   stackable会让导航栏以堆积的方式适应屏幕-->
            <h2 class="ui teal header item">管理后台</h2>  <!--item让这部分成为导航栏的条目-->
            <a href="" class="my-item item my-mobile-hide"><i class="home icon"></i>博客</a>
            <a href="" class="active my-item item my-mobile-hide"><i class="idea icon"></i>发布</a>
            <a href="" class="my-item item my-mobile-hide"><i class="tags icon"></i>列表</a>
            <div class="right my-mobile-hide menu">
                <div class="ui dropdown item"><!--dropdown效果是鼠标放在item时会让该部分更显眼；-->
                    <div class="text">
                        <img class="ui avatar image" src="../../static/image/山城.jpg">
                        承太郎
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="" class="item">注销</a>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div href="" class="ui my-menu toggle black icon button my-right-top my-mobile-show">
        <i class="sidebar icon"></i><!--三条横杠图标-->
    </div>
</nav>
<div class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">
            <a href="#" th:href="@{/admin/blogs/input}" class="teal active item">发布</a>
            <a href="#" th:href="@{/admin/blogs}" class="item">列表</a>
        </div>

    </div>
</div>

<!--中间-->
<div class="my-container-small my-padding-large">
    <div class="ui container">
        <form id="blog-form" action="#" th:object="${blog}" th:action="@{/admin/blogs}" method="post" class="ui form">
            <input type="hidden" name="published">
            <input type="hidden" name="id" th:value="*{id}">
            <div class="required field"><!--required是必须填写，不填写会爆红-->
                <div class="ui left labeled input">
                    <div class="ui selection compact teal basic dropdown label"><!--compact效果是让label适应文本-->
                        <input type="hidden" value="原创" name="flag" th:value="*{flag}"><!--*{...}选择表达式一般跟在th:object后，直接选择object中的属性-->
                        <i class="dropdown icon"></i>
                        <div class=" text">原创</div>
                        <div class="menu">
                            <div class="item" data-value="原创">原创</div>
                            <div class="item" data-value="转载">转载</div>
                            <div class="item" data-value="翻译">翻译</div>
                        </div>
                    </div>
                    <input type="text" name="title" th:value="*{title}" placeholder="标题">
                </div>
            </div>

            <div class="field">
                <div id="md-content" style="z-index: 1!important;"><!-- z-index是叠放层次，置为1，全屏写字的时候就不会被其他组件挡住-->
                    <textarea placeholder="博客内容" name="content" style="display: none" th:text="*{content}"></textarea>
                </div>
            </div>

            <div class="two fields">
                <div class="field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">分类</label>
                        <div class="ui fluid selection dropdown">
                            <input type="hidden" name="type.id" th:value="*{type}!=null? *{type.id}">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div th:each="type : ${types}" class="item" data-value="1" th:data-value="${type.id}" th:text="${type.name}">Error</div>
                                <!--/*-->
                                <div class="item" data-value="2">Log</div>
                                <!--*/-->
                            </div>
                        </div>
                    </div>
                </div>
                <div class="field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">标签</label>
                        <div class="ui fluid multiple search selection dropdown">
                            <!--multiple效果是让下拉式列表多选和删除标签，search效果是可以直接在列表搜索标签-->
                            <input type="hidden" name="tagId" th:value="*{tagId}">
                            <i class="dropdown icon"></i>
                            <div class="default text">标签</div>
                            <div class="menu">
                                <div th:each="tag: ${tags}" class="item" data-value="1" th:data-value="${tag.id}" th:text="${tag.name}">Java</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="field">
                <div class="ui left labeled input">
                    <label class="ui teal basic label">首图</label>
                    <input type="text" name="firstPicture" th:value="*{firstPicture}" placeholder="首页引用地址">
                </div>
            </div>

            <!--short description-->
            <div class="required field">
                <textarea required="required" name="description" th:text="*{description}" placeholder="max 200 char" maxlength="200"></textarea>
            </div>

            <div class="inline fields">
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend" checked th:checked="*{recommend}" class="hidden">
                        <label for="recommend">推荐</label><!--其label中的for的值是服务元素的Id，绑定指定id的元素，点击label后会激活相应的控件-->
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="shareStatement" name="shareStatement" th:checked="*{shareStatement}" class="hidden">
                        <label for="shareStatement">转载声明</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="appreciation" name="appreciation" th:checked="*{appreciation}" class="hidden">
                        <label for="appreciation">赞赏</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="commentabled" name="commentabled" th:checked="*{commentabled}" class="hidden">
                        <label for="commentabled">评论</label>
                    </div>
                </div>
            </div>

            <div class="ui error message"></div>

            <div class="ui right aligned container">
                <button class="ui button" type="button" onclick="window.history.go(-1)">返回</button>
                <!--onclick="window.history.go(-1)"效果是回到原来界面-->
                <button type="button" id="save-btn" class="ui secondary button">保存</button>
                <button type="button" id="publish-btn" class="ui teal button">发布</button>
            </div>

        </form>
    </div>
</div>

<!--底部-->
<footer th:replace="admin/_fragments :: footer" class="ui inverted vertical segment my-padding-massive">
    <div class="ui container diy_dp">
        <div class="ui stackable center aligned inverted divided grid">
            <div class="three wide column">
                <img src="../../static/image/微信.jpg" class="ui rounded image centered aligned" alt="" style="width: 130px">
            </div>

            <div class="three wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list"></div>
                <a href="" class="item">碧蓝航线攻略</a><br>
                <a href="" class="item">游戏抽奖技巧</a><br>
                <a href="" class="item">如何与傻逼交流</a>
            </div>

            <div class="three wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list"></div>
                <a href="" class="item">碧蓝航线攻略</a><br>
                <a href="" class="item">游戏抽奖技巧</a><br>
                <a href="" class="item">如何与傻逼交流</a>
            </div>

            <div class="seven wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <p class="my-text-spaced my-text-thin my-opacity-mini">这是我的个人博客，赶紧进去看看，你们不要不知好歹</p>
            </div>

        </div>
        <div class="ui inverted section divider"></div>
        <p class="my-text-spaced my-text-thin my-opacity-tiny">Copyright @ 2021-2022 MrWuu Designed by MrWuu</p>
    </div>

</footer>

<!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.js"></script>
<script src="../../static/lib/editormd/editormd.min.js"></script>
<!--/*/</th:block>/*/-->

<script>

    //初始化markdown编译器
    var contentEditor;
    $(function () {
        contentEditor = editormd("md-content", {
            width: "100%",
            height: 640,
            syncScrolling: "single",
     //       path: "../../static/lib/editormd/lib/"  /*lib后面有个/*/
             path: "/lib/editormd/lib/"
        });
    });

    $('.my-menu.toggle').click(function () {
        $('.my-item').toggleClass('my-mobile-hide');
        /*toggleClass效果：点击之后如果有my-mobile-hide这一个样式就去除掉
        如果没有则加上去*/
        /*这个js原理是先获取.my-menu toggle的作用域再把后面点击之后的效果加上来
            点击效果是由获取.my-item的作用域,加上toggleClass给的功能组成的*/
    });

    $('.ui.dropdown').dropdown({
        on: 'hover'
    })
    /*效果是鼠标放到ui dropdown样式上，里面的内容就会出来，例：鼠标放在头像上显示注销*/
    ;

    $('.ui.form').form({   /*获取ui.form表单，调用form方法*/
        fields: { /*指定区域*/
            title: {
                identifier: 'title', /*根据name指定生效在哪个组件*/
                rules: [{       /*指定规则*/
                    type: 'empty',  /*非空验证*/
                    prompt: '标题：请输入博客标题' /*提示内容*/
                }]
            },
            content : {
                identifier: 'content',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客内容'
                }]
            },
            typeId : {
                identifier: 'type.id',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客分类'
                }]
            },
            firstPicture : {
                identifier: 'firstPicture',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客首图'
                }]
            },
            description : {
                identifier: 'description',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客描述'
                }]
            }
        }
    });

    $('#save-btn').click(function () {
        $('[name="published"]').val(false);
        $('#blog-form').submit();
    });


    $('#publish-btn').click(function () {
        $('[name="published"]').val(true);
        $('#blog-form').submit();
    });

</script>

</body>
</html>